package com.panda.list.allapps;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.panda.list.R;
import com.panda.list.adapter.ApplicationAdapter;
import com.panda.list.info.ApplicationInfo;
import com.panda.list.utils.FastBitmapDrawable;

public class AllAppsAdapter extends ApplicationAdapter {

	ArrayList<ApplicationInfo> mInfo;
	Holder holder;

	Context mContext;
	LayoutInflater inflater;

	public AllAppsAdapter(Context context) {
		mContext = context;		
		inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mInfo = getAppList();

		setListener(this);
	}

	@Override
	public int getCount() {
		return mInfo.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView != null) {
			holder = (Holder) convertView.getTag();
		} else {

			convertView = inflater.inflate(R.layout.allapps_grid_item, null);

			holder = new Holder();
			holder.textView = (TextView) convertView.findViewById(R.id.allapps_grid_item_textview);

			convertView.setTag(holder);
		}

		holder.textView.setText(mInfo.get(position).getTitle());
		holder.textView.setCompoundDrawablesWithIntrinsicBounds(null, new FastBitmapDrawable(mInfo.get(position).bitmap), null, null);

		return convertView;
	}

	private class Holder {
		TextView textView;
	}

	@Override
	public void onNotifyDataChanged() {
		notifyDataSetChanged();
	}

	@Override
	public void notifyDataSetChanged() {
		super.notifyDataSetChanged();
	}
}
